package com.rnkrsoft.suyan.config.server.ajax.authority.mock;

import com.rnkrsoft.reflection4j.extension.Extension;
import com.rnkrsoft.suyan.config.server.ajax.authority.AuthorityAuthenticator;
import com.rnkrsoft.suyan.config.server.ajax.authority.AuthorityContext;
import com.rnkrsoft.suyan.config.server.ajax.authority.Menu;
import com.rnkrsoft.suyan.config.server.ajax.authority.MenuItem;

import java.util.Arrays;
import java.util.List;

@Extension("mock")
public class MockAuthorityAuthenticator implements AuthorityAuthenticator {
    @Override
    public boolean hasAuthority(AuthorityContext authorityContext) {
        return true;
    }

    @Override
    public List<Menu> menus(AuthorityContext authorityContext) {
        Menu menu1 = Menu.builder().application("test-app").product("demo1").build();
        MenuItem item1 = MenuItem.builder().application("test-app").product("demo1").action("action1").version("1.0.0").build();
        MenuItem item2 = MenuItem.builder().application("test-app").product("demo1").action("action2").version("1.0.0").build();
        menu1.getItems().add(item1);
        menu1.getItems().add(item2);
        Menu menu2 = Menu.builder().application("test-app").product("demo2").build();
        MenuItem item3 = MenuItem.builder().application("test-app").product("demo2").action("action1").version("1.0.0").build();
        MenuItem item4 = MenuItem.builder().application("test-app").product("demo2").action("action2").version("1.0.0").build();
        menu2.getItems().add(item3);
        menu2.getItems().add(item4);
        return Arrays.asList(menu1, menu2);
    }
}
